[USER (data scientist)]: Great! We have a new competitor named 'Raonic M.'. I need to find the win rates, head-to-head records against other players in the affected matches, and performance on the same surface as the tournament for this new competitor. Please provide a dataframe with Player Names, Win Rates, Head-to-Head Records, and Surface Performance.

[YOU (AI assistant)]: To find the win rates, head-to-head records, and surface performance for 'Raonic M.', you can use the following code:
'''
import pandas as pd  
  
# Load the dataset  
atp_tennis = pd.read_csv("atp_tennis.csv")  
  
# Find Federer matches  
federer_matches = atp_tennis[(atp_tennis['Player_1'] == 'Federer R.') | (atp_tennis['Player_2'] == 'Federer R.')]  
federer_opponents = federer_matches['Player_1'].where(federer_matches['Player_1'] != 'Federer R.', federer_matches['Player_2']).unique()  
  
def calculate_performance(player, opponent, data):  
    player_matches = data[((data['Player_1'] == player) & (data['Player_2'] == opponent)) | ((data['Player_1'] == opponent) & (data['Player_2'] == player))]  
    total_matches = len(player_matches)  
    wins = len(player_matches[player_matches['Winner'] == player])  
    win_rate = wins / total_matches if total_matches > 0 else 0  
  
    h2h_record = wins / total_matches if total_matches > 0 else 0  
  
    player_surface_matches = player_matches[player_matches['Surface'] == data[data['Player_1'] == player]['Surface'].iloc[0]]  
    player_surface_wins = len(player_surface_matches[player_surface_matches['Winner'] == player])  
    surface_performance = player_surface_wins / player_surface_matches.shape[0] if player_surface_matches.shape[0] > 0 else 0  
  
    return win_rate, h2h_record, surface_performance  
  
# Initialize an empty dataframe for storing the results  
player_stats = pd.DataFrame(columns=['Player', 'Opponent', 'Win Rate', 'Head-to-Head', 'Surface Performance'])  
  
# Loop through Federer's opponents  
for opponent in federer_opponents:  
    # Calculate win rate, head-to-head record, and surface performance for Raonic M. against each opponent  
    win_rate, h2h_record, surface_performance = calculate_performance('Raonic M.', opponent, atp_tennis)  
  
    # Append the results to the dataframe  
    player_stats = pd.concat([player_stats, pd.DataFrame({'Player': ['Raonic M.'], 'Opponent': [opponent], 'Win Rate': [win_rate], 'Head-to-Head': [h2h_record], 'Surface Performance': [surface_performance]})], ignore_index=True)  
  
# Display the resulting dataframe  
print(player_stats)  
'''

[USER (data scientist)]: You should differentiate results for different surface types.
My template of code snippet is:

---BEGIN CODE TEMPLATE---

import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

# YOUR SOLUTION BEGIN:
<code1>
[COMPLETE YOUR CODE] 
</code1>
# YOUR SOLUTION END

print(player_stats)

# save data
pickle.dump(player_stats,open("./pred_result/player_stats.pkl","wb"))

---END CODE TEMPLATE---

[YOU (AI assistant)]: Here is the new code:
'''
import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

# YOUR SOLUTION BEGIN:
